﻿<?php
defined('_JEXEC') or die('Restricted access');
?>

<script type="text/javascript">

	jQuery.noConflict();
	jQuery(document).ready(function(){
	    jQuery("#view_activity").click(function(){
			if(jQuery('#tyfrom').val() !='' && jQuery('#tyfrom').val() != '0'  && jQuery('#tyfrom').val() != '0000' && jQuery('#tyfrom').val() != 0){ 
				var tyfrom  = parseInt(jQuery('#tyfrom').val()) ;
			}else{
				var tyfrom = '0000' ;
			}
			var tmfrom = parseInt(jQuery('#tmfrom').val()) ;
			var tdfrom = parseInt(jQuery('#tdfrom').val()) ;
		    if(jQuery('#tyto').val() != '' && jQuery('#tyto').val() != '0' && jQuery('#tyto').val() != '0000' && jQuery('#tyto').val() != 0 ){
			    var tyto  = parseInt(jQuery('#tyto').val()) ;
		    }else{
		    	<?php 
					$cur_year =  explode('-', date('Y-m-d')) ;
				?>
				var tyto  = '<?php echo ($cur_year[0] + 1) ; ?>' ;
			}
		    var tmto = parseInt(jQuery('#tmto').val());
		    var tdto  = parseInt(jQuery('#tdto').val());
		    var tfrom_day = new Date(tyfrom, tmfrom, tdfrom);
		    var tto_day = new Date(tyto, tmto, tdto);
		    if(tto_day < tfrom_day){
		    	alert('"From date or To date is not correct."') ;
				return false ;
		   	}else{
	        	jQuery("#transactions").text('Loading...').load('<?php print JRoute::_('index.php?option=com_wrd&controller=profile&layout=fil_tran&tmpl=component',false); ?>',{'uid':<?php echo empty($this->data->user_id) ? 0 : $this->data->user_id ;?>,'mid':<?php echo empty($this->data->member_id) ? 0 : $this->data->member_id ;?>,'tyfrom':jQuery('#tyfrom').val(), 'tmfrom':jQuery('#tmfrom').val(), 'tdfrom':jQuery('#tdfrom').val(), 'tyto':jQuery('#tyto').val(), 'tmto':jQuery('#tmto').val(), 'tdto':jQuery('#tdto').val()});
		   	}
	    });
	});

</script>


<div class="row-fluid">
	<div class="alert">
		<table>
			 <tr>
			 	<td>
				 	<table>
					 	<tr>
							<td colspan='9'>
								<?php if(!empty($this->data->member_id)):?>
								<span style='width:150px; padding-right: 30px;'>Member ID assigned</span><span style='padding-right: 30px;'><strong><?php echo $this->data->member_id ; ?></strong></span>
								<?php endif ; 
									if(!empty($this->data->l_name) || !empty($this->data->f_name)):
								?>
								<span style='width:150px; padding-right: 30px;'>Member Name</span><span><strong><?php echo $this->data->l_name.' '.$this->data->f_name ; ?></strong></span>
								<?php endif; ?>
							</td>
						</tr>
						<tr>
							<td>
							<?php
								echo '<span style="padding-right: 10px;">From</span><br>';
								echo $this->lists['tyfrom'] ;
								echo $this->lists['tmfrom'] ;
								echo $this->lists['tdfrom'] ;
								echo '<br><span style="padding: 0 10px;">To</span><br>';
								echo $this->lists['tyto'] ;
								echo $this->lists['tmto'] ;
								echo $this->lists['tdto'] ;
							?>
								<br>
								<input type='button' value="Go" id="view_activity" class="view_activity" />
							</td>
				 		</tr>
			 		</table>
				</td>
				<td style="text-align: right ;">
			 		<?php if($this->user->authorise('wrd.profile.spending.add', 'com_wrd')): ?>
					<a href="index.php?option=com_wrd&controller=atransaction&task=add<?php if(!empty($this->data->member_id)){ echo '&vip_num='.$this->data->member_id ; } ?>">
						<img title="Add New" style="float: right ;" src="<?php echo JURI::base() .'/components/com_wrd/assets/images/add_new.png'?>">
			 		</a>
					<?php endif;?>
			 	</td>
			 </tr>
	 	</table>
 	</div>
 	
 	<div id='transactions'>
	 	<table class="table table-striped adminlist">
			 <tr class="headerTd">
				<th>Order</th>
			 	<td style="text-align: center;"><b>Check number</b></td>				
			 	<td style="text-align: center;"><b>Date receipt</b></td>			
			 	<td style="text-align: center;"><b>Outlet</b></td>			
			 	<td style="text-align: center;"><b>Pax</b></td>				
			 	<td><b>Food</b></td>				
			 	<td><b>Beverage</b></td>				
			 	<td><b>Other</b></td>
			 	<td><b>Discount</b></td>			
			 	<td><b>Netsale</b></td>				
			 	<td><b>Services Charges</b></td>		
			 	<td><b>Vat</b></td>
			 	<td><b>Total</b></td>
			 </tr>
			 <?php if($this->transaction > 0): ?>
					
				 <?php $count = 0; foreach($this->transaction as $w => $item): 
				 	$cls = 1;
				 	if($w%2) $cls = 0;
				 ?>
				 	<tr class="<?php echo "row$cls"; ?>">
						<td><?php $count ++; echo $count; ?></td>
				 		<td><?php //echo "<pre>";print_r($item); ?><a href="<?php echo JURI::root(); ?>administrator/index.php?option=com_wrd&controller=profile&id=<?php echo $this->data->id;?>&transaction_id=<?php echo $item->transaction_id;?>&outlet=<?php echo $item->outletcode ;?>&layout=detailtransaction" target="_blank"><?php echo $item->transaction_id ?></a></td>				
					 	<td><?php echo date("d-m-Y H:i:s",strtotime($item->date_receipt)) ?></td>			
					 	<td><?php echo $item->outletname ; ?></td>			
					 	<td><?php echo $item->pax ?></td>				
					 	<td style="text-align: right;"><?php echo number_format($item->food,0,'.',',') ?></td>				
					 	<td style="text-align: right;"><?php echo number_format($item->beverage,0,'.',',') ?></td>				
					 	<td style="text-align: right;"><?php echo number_format($item->other,0,'.',',') ?></td>
					 	<td style="text-align: right;"><?php echo number_format($item->discount,0,'.',',') ?></td>
					 	<td style="text-align: right;"><?php echo number_format($item->netsale,0,'.',',') ?></td>				
					 	<td style="text-align: right;"><?php echo number_format($item->sc,0,'.',',') ?></td>		
					 	<td style="text-align: right;"><?php echo number_format($item->vat,0,'.',',') ?></td>
					 	<td style="text-align: right;"><?php echo number_format($item->total,0,'.',',') ?></td>
					 	
				 	</tr>
				 <?php endforeach; ?>
			 <?php endif; ?>
			 <tr>
			 	<td colspan='14'><hr style='border: 1px dashed #333 ; ' /></td>
		 	 </tr>
			
			 <tr>
			 	<td colspan='14'>
					<table width='101%'>
						<tr class="row1">
							<td style="background: none;border: none;" width='650px'>&nbsp;</td>
							<td>PTD Total Spending from vip_wrd_spending_summary (<b style='color: red;'>Định tester </b>)</td>
							<td align="right"><?php 
							
							echo number_format($this->totalSpending->total, 0,'.',','); ?></td>
						</tr>
						<tr class="row1">
							<td style="background: none;border: none;" width='650px'>&nbsp;</td>
							<td>PTD Total Spending from vip_wrd_profile (<b style='color: red;'>Định tester </b>)</td>
							<td align="right"><?php 
							
							echo number_format($this->data->total_spend, 0,'.',','); ?></td>
						</tr>
						<tr class="row1">
							<td style="background: none;border: none;" width='650px'>&nbsp;</td>
							<td>PTD Total Spending</td>
							<td align="right"><?php echo number_format($this->total_cost, 0,'.',','); ?></td>
						</tr>
						<tr class="row1">
							<td style="background: none;border: none;">&nbsp;</td>
							<td>PTD Points Obtained</td>
							<td align="right">
								<?php echo number_format(($this->p_o_u_e), 0,'.',',');
									
								?>
							</td>
						</tr>
						<tr class="row1">
							<td style="background: none;border: none;">&nbsp;</td>
							<td>Points Redempted</td>
							<td align="right"><?php echo number_format($this->total_points_used, 0,'.',',') ;?></td>
						</tr>
						<tr class="row1">
							<td style="background: none;border: none;">&nbsp;</td>
							<td>Points Balance</td>
							<td align="right"><?php echo number_format($this->p_o_u_e-$this->total_points_used, 0,'.',',') ;
								
							?></td>
							</tr>
						</table>
					</td>
				 </tr>
			</table>
		</div>
</div>